﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SmartProject.BusinessObjects
{
    public class FileType : Reference
    {
        public FileType()
        {
            string[] fileTypes = { "jpg", "png", "txt", "doc", "xml" };
            base.Initialize("FileTypes", fileTypes);
        }

        public int GetFileTypeId(string filename)
        {
            System.IO.FileInfo info = new System.IO.FileInfo(filename);
            string ext = info.Extension.Replace(".", "").ToLower();
            return GetId(ext, true);
        }

        public string GetMimeType(string fileType)
        {
            switch (fileType)
            {
                case "jpg":
                    return "image/jpeg";

                case "png":
                    return "image/png";

                case "txt":
                    return "text/txt";

                case "doc":
                    return "application/msword";

                case "xml":
                    return "text/xml";
            }
            return String.Empty;
        }

        public bool IsImageFile(int fileTypeId)
        {
           return IsImageFile(GetValue(fileTypeId));
        }

        public bool IsImageFile(string fileType)
        {
            switch (fileType)
            {
                case "jpg":
                    return true;

                case "png":
                    return true;

                default:
                    return false;
            }
        }
    }
}
